package indi.wshape1.takeawaydeliveryinfo.config;

import indi.wshape1.takeawaydeliveryinfo.interceptor.DirectAccessInterceptor;
import indi.wshape1.takeawaydeliveryinfo.interceptor.FirstVisitInterceptor;
import indi.wshape1.takeawaydeliveryinfo.interceptor.LoginInterceptor;
import indi.wshape1.takeawaydeliveryinfo.service.AdminService;
import indi.wshape1.takeawaydeliveryinfo.service.RootService;
import indi.wshape1.takeawaydeliveryinfo.service.SenderService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Wshape1
 * @version 1.0
 * @description 配置类
 * 2023年1月17日17点18分： 麻了！ 忘记排除/login害我debug半天
 * @since 2023-01-17
 */

@Configuration
@MapperScan("indi.wshape1.takeawaydeliveryinfo.mapper")
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    private SenderService senderService;
    @Autowired
    private AdminService adminService;
    @Autowired
    private RootService rootService;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new FirstVisitInterceptor())
                .addPathPatterns("/**")
                .order(0);

        // 拦截未登录用户前往后台页面
        registry.addInterceptor(new LoginInterceptor(senderService, adminService, rootService))
                .addPathPatterns("/", "/page/**", "/more/**", "/change/**", "/quit/**")
                .order(1);

        // 拦截直接访问HTML
        registry.addInterceptor(new DirectAccessInterceptor())
                .addPathPatterns("/**/*.html", "/**/*.htm")
                .order(1);

    }


}
